package com.bz.xtcx.manager.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class WzStrUtil extends StringUtils {
    public static boolean isMobile(String ms) {
        if (isBlank(ms)) {
            return false;
        }
        if (11 != ms.length()) {
            return false;
        }
        String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(ms);
        if (m.matches()) {
            return true;
        }
        return false;
    }

    public static boolean isPhone(String ms) {
        if (isBlank(ms)) {
            return false;
        }
        String regex = "\\d{7,12}";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(ms);
        if (m.matches()) {
            return true;
        }
        return false;
    }

    public static boolean isEmail(String es) {
        if (isBlank(es)) {
            return false;
        }
//        String regex = "^([a-z0-9A-Z]+[-|\\\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\\\.)+[a-zA-Z]{2,}$";
        String regex = "^[A-Za-z0-9]+([-_.][A-Za-z0-9]+)*@([A-Za-z0-9]+[-.])+[A-Za-z0-9]{2,}$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(es);
        if (m.matches()) {
            return true;
        }
        return false;
    }

    public static boolean isNumber(String ns) {
        if (isBlank(ns)) {
            return false;
        }
        String regex = "^[0-9]+$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(ns);
        if (m.matches()) {
            return true;
        }
        return false;
    }
}
